//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-2015, Egret Technology Inc.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-2015, Egret Technology Inc.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////

class LoadingUI extends egret.Sprite {

    public constructor() {
        super();
        this.createView();
    }

    private state: number = 0;
    private loadingView: LoadingView;
    private createView(): void {
        RES.getResByUrl("resource/assets/view_loading.png",this.loadComplete,this,RES.ResourceItem.TYPE_IMAGE);
        RES.getResByUrl("resource/assets/word_loading.png",this.loadComplete,this,RES.ResourceItem.TYPE_IMAGE);
        RES.getResByUrl("resource/assets/loading.png",this.loadComplete,this,RES.ResourceItem.TYPE_IMAGE);
    }

    private loadComplete(): void {
        this.state += 1;
        if(this.state == 3) {
            this.loadingView = new LoadingView();
            this.addChild(this.loadingView);
        }
    }

    public setProgress(current: number,total: number): void {
        if(this.loadingView && this.contains(this.loadingView)) {
//            this.loadingView.setLoading(current,total);
        }
    }
}


//class LoadingUI extends eui.Component {
//
//    private im_loading:eui.Image;
//    private load1:eui.Image;
//    private load2: eui.Image;
//    private load3: eui.Image;
//    private timer:egret.Timer;
//    private step:number = 0;
//    
//    
//    public constructor() {
//        super();
//        this.skinName = "resource/skins/LoadingSkin.exml";
//    }
//
//    public createChildren() {
//        super.createChildren();
//        this.init();
//        
//    }
//    private init() {
////        egret.Tween.get(this,{ loop: true }).to({ t: Math.PI * 2 },800);
//        this.timer = new egret.Timer(200);
//        this.timer.addEventListener(egret.TimerEvent.TIMER,this.vdian,this);
//        this.timer.start();
//    }
//    
//    private vdian(){
//        this.step++;
//        if(this.step==2){
//            this.load2.visible = true;
//            this.load3.visible = false;
//        }else if(this.step == 3) {
//            this.load2.visible = true;
//            this.load3.visible = true;
//        } else if(this.step == 4) {
//            this.load2.visible = false;
//            this.load3.visible = false;
//            this.step = 1;
//        }
//    }
//    
//    private _t: number = 0;
//    get t(): number { return this._t; }
//    set t(value: number) {
//        this._t = value;
//        this.im_loading.scaleX = Math.sin(value) * 0.05 + 1;
//        this.im_loading.scaleY = Math.sin(value - Math.PI / 2) * 0.05 + 1;
//    }
//    
////    private textField:egret.TextField;
////
////    private createView():void {
////        this.textField = new egret.TextField();
////        this.addChild(this.textField);
////        this.textField.y = 300;
////        this.textField.width = 480;
////        this.textField.height = 100;
////        this.textField.textAlign = "center";
////    }
////
////    public setProgress(current:number, total:number):void {
////        this.textField.text = `Loading...${current}/${total}`;
////    }
//}
